﻿using System;
using System.Collections.Generic;
using Helpers;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.Roster;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

namespace TaleWorlds.CampaignSystem.LogEntries
{
	// Token: 0x020002E7 RID: 743
	public class VillageStateChangedLogEntry : LogEntry, IWarLog
	{
		// Token: 0x06002B80 RID: 11136 RVA: 0x000B8292 File Offset: 0x000B6492
		internal static void AutoGeneratedStaticCollectObjectsVillageStateChangedLogEntry(object o, List<object> collectedObjects)
		{
			((VillageStateChangedLogEntry)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
		}

		// Token: 0x06002B81 RID: 11137 RVA: 0x000B82A0 File Offset: 0x000B64A0
		protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
		{
			base.AutoGeneratedInstanceCollectObjects(collectedObjects);
			collectedObjects.Add(this.Village);
			collectedObjects.Add(this.RaiderPartyMapFaction);
			collectedObjects.Add(this.VillageRealmWhenRaided);
			collectedObjects.Add(this.RaidLeader);
			collectedObjects.Add(this._witnesses);
		}

		// Token: 0x06002B82 RID: 11138 RVA: 0x000B82F0 File Offset: 0x000B64F0
		internal static object AutoGeneratedGetMemberValueVillage(object o)
		{
			return ((VillageStateChangedLogEntry)o).Village;
		}

		// Token: 0x06002B83 RID: 11139 RVA: 0x000B82FD File Offset: 0x000B64FD
		internal static object AutoGeneratedGetMemberValueOldState(object o)
		{
			return ((VillageStateChangedLogEntry)o).OldState;
		}

		// Token: 0x06002B84 RID: 11140 RVA: 0x000B830F File Offset: 0x000B650F
		internal static object AutoGeneratedGetMemberValueNewState(object o)
		{
			return ((VillageStateChangedLogEntry)o).NewState;
		}

		// Token: 0x06002B85 RID: 11141 RVA: 0x000B8321 File Offset: 0x000B6521
		internal static object AutoGeneratedGetMemberValueRaiderPartyMapFaction(object o)
		{
			return ((VillageStateChangedLogEntry)o).RaiderPartyMapFaction;
		}

		// Token: 0x06002B86 RID: 11142 RVA: 0x000B832E File Offset: 0x000B652E
		internal static object AutoGeneratedGetMemberValueVillageRealmWhenRaided(object o)
		{
			return ((VillageStateChangedLogEntry)o).VillageRealmWhenRaided;
		}

		// Token: 0x06002B87 RID: 11143 RVA: 0x000B833B File Offset: 0x000B653B
		internal static object AutoGeneratedGetMemberValueRealmsAtWarWhenRaided(object o)
		{
			return ((VillageStateChangedLogEntry)o).RealmsAtWarWhenRaided;
		}

		// Token: 0x06002B88 RID: 11144 RVA: 0x000B834D File Offset: 0x000B654D
		internal static object AutoGeneratedGetMemberValueRaidLeader(object o)
		{
			return ((VillageStateChangedLogEntry)o).RaidLeader;
		}

		// Token: 0x06002B89 RID: 11145 RVA: 0x000B835A File Offset: 0x000B655A
		internal static object AutoGeneratedGetMemberValue_witnesses(object o)
		{
			return ((VillageStateChangedLogEntry)o)._witnesses;
		}

		// Token: 0x06002B8A RID: 11146 RVA: 0x000B8368 File Offset: 0x000B6568
		public VillageStateChangedLogEntry(Village village, Village.VillageStates oldState, Village.VillageStates newState, MobileParty raiderParty)
		{
			this.Village = village;
			this.OldState = oldState;
			this.NewState = newState;
			this.RaiderPartyMapFaction = raiderParty.MapFaction;
			this.VillageRealmWhenRaided = village.Settlement.MapFaction;
			this.RealmsAtWarWhenRaided = this.RaiderPartyMapFaction.IsAtWarWith(this.VillageRealmWhenRaided);
			this.RaidLeader = raiderParty.LeaderHero;
			if (raiderParty.LeaderHero == Hero.MainHero)
			{
				Dictionary<Hero, short> dictionary = new Dictionary<Hero, short>();
				foreach (TroopRosterElement troopRosterElement in MobileParty.MainParty.MemberRoster.GetTroopRoster())
				{
					if (troopRosterElement.Character.HeroObject != null && !dictionary.ContainsKey(troopRosterElement.Character.HeroObject))
					{
						dictionary.Add(troopRosterElement.Character.HeroObject, 1);
					}
				}
				this._witnesses = dictionary.GetReadOnlyDictionary<Hero, short>();
			}
		}

		// Token: 0x06002B8B RID: 11147 RVA: 0x000B846C File Offset: 0x000B666C
		public bool IsRelatedToWar(StanceLink stance, out IFaction effector, out IFaction effected)
		{
			IFaction faction = stance.Faction1;
			IFaction faction2 = stance.Faction2;
			IFaction raiderPartyMapFaction = this.RaiderPartyMapFaction;
			effector = ((raiderPartyMapFaction != null) ? raiderPartyMapFaction.MapFaction : null);
			IFaction villageRealmWhenRaided = this.VillageRealmWhenRaided;
			effected = ((villageRealmWhenRaided != null) ? villageRealmWhenRaided.MapFaction : null);
			return this.NewState == Village.VillageStates.Looted && ((this.VillageRealmWhenRaided == faction && this.RaiderPartyMapFaction == faction2) || (this.VillageRealmWhenRaided == faction2 && this.RaiderPartyMapFaction == faction));
		}

		// Token: 0x06002B8C RID: 11148 RVA: 0x000B84E4 File Offset: 0x000B66E4
		public override string ToString()
		{
			TextObject textObject = new TextObject("{=!}Village named {SETTLEMENT} state changed from {OLD_STATE} to {NEW_STATE}", null);
			textObject.SetTextVariable("SETTLEMENT", this.Village.Settlement.Name);
			textObject.SetTextVariable("OLD_STATE", this.OldState.ToString());
			textObject.SetTextVariable("NEW_STATE", this.NewState.ToString());
			return textObject.ToString();
		}

		// Token: 0x06002B8D RID: 11149 RVA: 0x000B8558 File Offset: 0x000B6758
		public override int GetAsRumor(Settlement talkSettlement, ref TextObject comment)
		{
			int result = 0;
			if (this.NewState == Village.VillageStates.Looted && this.Village.Settlement.MapFaction == talkSettlement.MapFaction)
			{
				comment = new TextObject("{=nV1xbbM6}So I hear {ENEMY_NAME} burned and pillaged {VILLAGE_NAME}. Bastards...", null);
				comment.SetTextVariable("ENEMY_NAME", FactionHelper.GetTermUsedByOtherFaction(this.RaiderPartyMapFaction, talkSettlement.MapFaction, false));
				comment.SetTextVariable("VILLAGE_NAME", this.Village.Name);
				result = 10;
			}
			return result;
		}

		// Token: 0x06002B8E RID: 11150 RVA: 0x000B85D0 File Offset: 0x000B67D0
		public override void GetConversationScoreAndComment(Hero talkTroop, bool findString, out string comment, out ImportanceEnum score)
		{
			short num;
			if (this._witnesses == null || !this._witnesses.TryGetValue(talkTroop, out num))
			{
				num = -2;
			}
			score = ImportanceEnum.Zero;
			comment = "";
			if (talkTroop.MapFaction != Hero.MainHero.MapFaction && talkTroop.MapFaction == this.VillageRealmWhenRaided && this.Village.Settlement.OwnerClan == talkTroop.Clan && talkTroop.Clan.Leader == talkTroop && this.RaidLeader == Hero.MainHero)
			{
				score = ImportanceEnum.Important;
				comment = "str_comment_you_raided_my_village";
				MBTextManager.SetTextVariable("SETTLEMENT_NAME", this.Village.Name, false);
				return;
			}
			if (num == 1 && this.NewState == Village.VillageStates.BeingRaided && this.Village.Settlement.Culture == talkTroop.Culture && this.RaiderPartyMapFaction.Culture != talkTroop.Culture)
			{
				score = ImportanceEnum.QuiteImportant;
				comment = "str_comment_we_raided_my_people";
				MBTextManager.SetTextVariable("VILLAGE_NAME", this.Village.Name, false);
				return;
			}
			if (num == 1 && this.NewState == Village.VillageStates.BeingRaided && this.RaiderPartyMapFaction.MapFaction.IsKingdomFaction && this.RealmsAtWarWhenRaided)
			{
				score = ImportanceEnum.QuiteImportant;
				comment = "str_comment_we_raided_enemy_village";
				MBTextManager.SetTextVariable("VILLAGE_NAME", this.Village.Name, false);
				MBTextManager.SetTextVariable("ENEMY_NAME", this.VillageRealmWhenRaided.InformalName, false);
				return;
			}
			if (num == 1 && this.NewState == Village.VillageStates.BeingRaided && !this.RealmsAtWarWhenRaided)
			{
				score = ImportanceEnum.QuiteImportant;
				comment = "str_comment_we_raided_neutral_village";
				MBTextManager.SetTextVariable("VILLAGE_NAME", this.Village.Name, false);
				MBTextManager.SetTextVariable("VILLAGE_FACTION", this.VillageRealmWhenRaided.InformalName, false);
			}
		}

		// Token: 0x04000D07 RID: 3335
		[SaveableField(340)]
		public readonly Village Village;

		// Token: 0x04000D08 RID: 3336
		[SaveableField(341)]
		public readonly Village.VillageStates OldState;

		// Token: 0x04000D09 RID: 3337
		[SaveableField(342)]
		public readonly Village.VillageStates NewState;

		// Token: 0x04000D0A RID: 3338
		[SaveableField(343)]
		public readonly IFaction RaiderPartyMapFaction;

		// Token: 0x04000D0B RID: 3339
		[SaveableField(344)]
		public readonly IFaction VillageRealmWhenRaided;

		// Token: 0x04000D0C RID: 3340
		[SaveableField(345)]
		public readonly bool RealmsAtWarWhenRaided;

		// Token: 0x04000D0D RID: 3341
		[SaveableField(346)]
		private readonly MBReadOnlyDictionary<Hero, short> _witnesses;

		// Token: 0x04000D0E RID: 3342
		[SaveableField(347)]
		public readonly Hero RaidLeader;
	}
}
